package com.yy.micro.magic.data.model.base;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.*;

@MappedSuperclass
public abstract class JpaObject implements DomainObject, AuditSupport {

    @Column(name = "create_by",nullable = false)
    private long createBy;
    @Column(name = "modified_by",nullable = false)
    private long modifiedBy;
    @Column(name = "create_time",nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date createTime;
    @Column(name = "modified_time",nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date modifiedTime;

    @Transient
    private final Set<String> ignoreProperties = new HashSet<>();
    {
        ignoreProperties.add("createdBy");
        ignoreProperties.add("modifiedBy");
        ignoreProperties.add("createdTime");
        ignoreProperties.add("modifiedTime");
    }

    @Override
    @Transient
    public Set<String> getIgnorePropertiesInEntitySync() {
        return this.ignoreProperties;
    }

    @PrePersist
    public void prePersist(){
        AuditHelper.update(this);
    }

    @PreUpdate
    public void preUpdate(){
        AuditHelper.update(this);
    }

    @Override
    public void setCreateTime(Date date) {
        this.createTime = date;
    }

    @Override
    public Date getCreateTime() {
        return createTime;
    }


    @Override
    public void setCreateBy(long userId) {
        this.createBy = userId;
    }

    @Override
    public long getCreateBy() {
        return this.createBy;
    }


    public void setModifiedBy(long modifiedBy) {
        this.modifiedBy = modifiedBy;
    }

    public long getModifiedBy() {
        return modifiedBy;
    }

    public void setModifiedTime(Date modifiedTime) {
        this.modifiedTime = modifiedTime;
    }

    public Date getModifiedTime() {
        return modifiedTime;
    }
}
